import { ss } from "@/utils/storage";

const LOCAL_NAME = "userStorage";

export interface UserInfo {
	avatar: string;
	name: string;
	description: string;
}

export interface UserState {
	userInfo: UserInfo;
}

export function defaultSetting(): UserState {
	return {
		userInfo: {
			avatar:
				"https://foruda.gitee.com/avatar/1677232740635907826/11289682_tomato-lrx_1661138148.png!avatar200",
			name: "TomatoLRX",
			description: "Star on it from TomatoLRX ",
		},
	};
}

export function getLocalState(): UserState {
	const localSetting: UserState | undefined = ss.get(LOCAL_NAME);
	return { ...defaultSetting(), ...localSetting };
}

export function setLocalState(setting: UserState): void {
	ss.set(LOCAL_NAME, setting);
}
